package fr.cyol.android.levaldesetoiles;

import android.app.AlertDialog;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;
import android.widget.TextView;

public class EtresActivity extends LeValDesEtoilesActivity {
	static final Integer[] NOMS_DES_ETRES = new Integer[]{
    		R.string.etre_accompli, R.string.etre_chevalier, R.string.etre_enfant,
    		R.string.etre_magicien, R.string.etre_spectre, R.string.etre_fou, 
    };

	static final Integer[] IMAGES_DES_ETRES = {
            R.drawable.etre_accompli, R.drawable.etre_chevalier, R.drawable.etre_enfant,
            R.drawable.etre_magicien, R.drawable.etre_spectre, R.drawable.etre_fou, 
    };
	
	static final Integer[] DESCRIPTION_DES_ETRES = new Integer[]{
		R.string.description_etre_accompli, R.string.description_etre_chevalier, R.string.description_etre_enfant,
		R.string.description_etre_magicien, R.string.description_etre_spectre, R.string.description_etre_fou, 
		
	};
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.lvde_etres);
        
        //Gestion de l'affichage du Grid
        GridView gridview = (GridView) findViewById(R.id.gridview_etres);
        gridview.setAdapter(new ImageAdapter(this, NOMS_DES_ETRES, IMAGES_DES_ETRES));

        gridview.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
                detailEtre(v, position);
            }
        });
        
    }
    
    //Appel du Dialog
    public void detailEtre(View vue, int position){
        LayoutInflater factory = LayoutInflater.from(this);
        final View alertDialogView = factory.inflate(R.layout.dialog_img_txt, null);
        Resources res = getResources();
    	AlertDialog.Builder dialogEtre = new AlertDialog.Builder(this);
    	dialogEtre.setView(alertDialogView);
    	dialogEtre.setTitle(res.getText(NOMS_DES_ETRES[position]));
    	dialogEtre.setMessage(res.getText(DESCRIPTION_DES_ETRES[position]));
    	
    	TextView textView = (TextView) alertDialogView
				.findViewById(R.id.grid_item_label);
		textView.setText(res.getText(NOMS_DES_ETRES[position]));
		 
		
		Drawable img = res.getDrawable(IMAGES_DES_ETRES[position]);
		textView.setCompoundDrawablesWithIntrinsicBounds(null, img, null, null);
    	dialogEtre.setNegativeButton(res.getText(R.string.fermer), null);
    	dialogEtre.show();
    }
}
